import java.util.Arrays;

public class Solution1620 {
    public int[] bestCoordinate(int[][] towers, int radius) {
        int[][] f=new int[51][51];
        for (int i=0;i<=50;i++){
            for (int j=0;j<=50;j++){
                for (int[] tower : towers) {
                    if (dis(new int[]{i,j},tower)<=radius){
                        f[i][j]+=(int)(tower[2]*1.0/(1.0+dis(new int[]{i,j},tower)));
                    }
                }
            }
        }
        int x=-1,y=-1,min=Integer.MIN_VALUE;
        for (int i=0;i<=50;i++){
            for (int j=0;j<=50;j++){
                if (f[i][j]>min){
                    x=i;
                    y=j;
                    min=f[i][j];
                }else if (f[i][j]==min){
                    if (i<x || i==x && j<y){
                        x=i;
                        y=j;
                        min=f[i][j];
                    }
                }
            }
        }
        return new int[]{x,y};
    }

    private double dis(int[] a, int[] b) {
        return Math.sqrt((a[0]-b[0])*(a[0]-b[0])+(a[1]-b[1])*(a[1]-b[1]));
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution1620().bestCoordinate(new int[][]{{1, 2, 5}, {2, 1, 7}, {3, 1, 9}}, 2)));
    }
}
